package com.rd.p2p.mobile.account;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.qdlc.p2p.biz.adapted.AdaptedServiceFactory;
import com.qdlc.p2p.biz.adapted.AdaptedWithdrawService;
import com.qdlc.p2p.common.core.ReturnResult;
import com.qdlc.p2p.dal.util.UserTypeUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.util.CollectionUtils;

import com.opensymphony.xwork2.ModelDriven;
import com.qdlc.p2p.biz.service.AccountBankService;
import com.qdlc.p2p.biz.service.AccountCashService;
import com.qdlc.p2p.biz.service.AccountService;
import com.qdlc.p2p.biz.service.UserIdentifyService;
import com.qdlc.p2p.biz.tpp.TppBaseInterface;
import com.qdlc.p2p.biz.tpp.TppServiceFactory;
import com.qdlc.p2p.biz.web.action.BaseAction;
import com.qdlc.p2p.dal.common.SystemConfigHelper;
import com.qdlc.p2p.dal.common.SystemConfigHelper.Nid;
import com.qdlc.p2p.dal.dto.Account;
import com.qdlc.p2p.dal.dto.AccountBank;
import com.qdlc.p2p.dal.dto.User;
import com.qdlc.p2p.dal.model.AccountBankModel;
import com.qdlc.p2p.dal.model.AccountCashModel;
import com.qdlc.p2p.dal.model.TppModel;

/**
 * 移动端-提现
 * 
 * @author wuhuan
 */
public class MobileCashAction extends BaseAction<AccountCashModel> implements ModelDriven<AccountCashModel> {
	@Resource
	private UserIdentifyService userIdentifyService;
	@Resource
	private AccountCashService accountCashService;
	@Resource
	private AccountBankService accountBankService;
	@Resource
	private AccountService accountService;

	AdaptedWithdrawService withdrawService = AdaptedServiceFactory.getService(AdaptedWithdrawService.class);

	/**
	 * 前往提现页面
	 * 
	 * @return
	 */
	@Action(value = "/mobile/usercenter/cash/newCash", results = {
			@Result(name = "newCash", type = "ftl", location = "/mobile/member/cash/newCash.html") })
	public String newCash() throws Exception {

		// 添加token
		saveToken("newCash");
		// 获取用户
		User user = getSessionUser();
		// 获取页面属性
		ReturnResult result = withdrawService.gotoNewCash(user);

		//修改图片路径
		List<AccountBank> bankList = (List<AccountBank> )result.getExtra("bankList");
		for (AccountBank accountBank : bankList) {
			String picPath = accountBank.getPicPath();
			picPath = picPath.replaceAll("mini", "weixin");
			accountBank.setPicPath(picPath);
		}

		result.addExtra("bankList",bankList);
		// 设置页面属性
		for(Map.Entry<String, Object> entry: result.getExtra().entrySet()){
			request.setAttribute(entry.getKey(), entry.getValue());
		}
		return "newCash";
	}

}
